﻿<cfsilent>
	<cfscript>
		
		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		stringAdvice = getProperty("serviceFactory").getBean("stringAdvice");
		
		teacherId = sessionAdvice.getAutherUserID();
		
		taskType = event.getArg("TT");
		taskId = event.getArg("TSK");
		evsId = event.getArg("ES");
		secureTicket = event.getArg("ST");
		
		/* 安全设置 */
		viewSecure = false;
		
		/* 首先做安全检查 */
		try {
			stringOrignal = decrypt( secureTicket, teacherId, "PBEWithMD5AndDES", "Hex");
			stringTest = evsId & taskType & taskId;
			
			if ( stringOrignal eq stringTest ) {
				viewSecure = true;
			}
		}
		catch(any excpt) {
		}
		
		if ( viewSecure ) {
			
			/* 评价体系相关设置 */
			sql = "SELECT 
						es_name, es_model, es_level 
					FROM 
						t_evaluate_system 
					WHERE 
						es_id = :evsId ";
		
			queryObj = new Query( datasource=application.dnsSlave );
			
			queryObj.addParam( name="evsId", value=evsId, cfsqltype="cf_sql_char" );

			rs_evs = queryObj.execute( sql=sql ).getResult();
			
			/* 评价体系观测点 */
			sql = "SELECT 
						level_order, tag_id, tag_order, tag_weight, question, 
						t_measure_set.m_id, t_measure_set.measure 
					FROM t_target 
						INNER JOIN t_measure_set ON t_measure_set.m_id = t_target.m_id 
					WHERE 
						es_id = :evsId ";
		
			queryObj = new Query( datasource=application.dnsSlave );
			
			queryObj.addParam( name="evsId", value=evsId, cfsqltype="cf_sql_char" );
		
			rs_target = queryObj.execute( sql=sql ).getResult();
		
		
			/* 评价体系选项 */
			sql = "SELECT 
						m_id, opt_name, opt_idx 
					FROM 
						t_measure_options ";
												
			queryObj = new Query( datasource=application.dnsSlave );
		
			rs_options = queryObj.execute( sql=sql ).getResult();

		}
		
	</cfscript>
</cfsilent>

<cfif viewSecure>

	<!--- 两段式评教 --->
	<cfif rs_evs.es_model eq "M2">
		
		<cfset L1 = 0 />
		
		<table id="sheetTable" class="UItable">
								
			<cfloop from="1" to="2" index="stageId">

			<cfscript>
							
				sql = "SELECT 
							tag_order, question, tag_weight 
						FROM 
							query 
						WHERE 
							level_order = :stageId 
							AND 
							tag_order LIKE '__00' 
						ORDER BY 
							tag_order ";
							
				queryObj = new Query( dbtype="query" );
				
				queryObj.setAttributes( query=rs_target );
				queryObj.addParam( name="stageId", value=stageId, cfsqltype="cf_sql_char" );

				rs_type = queryObj.execute( sql=sql ).getResult();

			</cfscript>

			<cfif rs_type.recordCount>
									
				<cfif stageId gt 1>
					<tr class="breakRows">
						<td colspan="3"></td>
					</tr>
				</cfif>
				<tr class="cellBorder cellHeader">
					<td colspan="3"><cfif stageId eq 1>课程进行期间<cfelse>课程结束后</cfif></td>
				</tr>
				<tr class="breakRows">
					<td colspan="3"></td>
				</tr>
			</cfif>
										
									
			<cfloop query="rs_type">
											
				<cfset L1++ />
											
				<tr class="cellBorder cellNotice">
					<td><span class="numeric"><cfoutput>#L1#</cfoutput></span></td>
					<td colspan="2"><cfoutput>#rs_type.question#</cfoutput></td>
				</tr>
									
				<cfscript>
		
					sql = "SELECT 
								tag_id, question, m_id, measure 
							FROM 
								query 
							WHERE 
								level_order = :stageId 
								AND 
								tag_order NOT LIKE '__00' 
								AND 
								tag_order LIKE :condition 
							ORDER BY 
								tag_order ";

					queryObj = new Query( dbtype="query" );
					
					queryObj.setAttributes( query=rs_target );
					queryObj.addParam( name="stageId", value=stageId, cfsqltype="cf_sql_char" );
					queryObj.addParam( name="condition", value=left(rs_type.tag_order, 2) & "__", cfsqltype="cf_sql_char" );

					rs_list = queryObj.execute( sql=sql ).getResult();
			
				</cfscript>
		
				<cfif rs_list.recordCount>
				
					<cfset L2 = 0 />

					<cfloop query="rs_list">
						
						<cfset L2++ />
						
						<cfscript>

							targetId = rs_list.tag_id;
							measureId = rs_list.m_id;
							measure = rs_list.measure;
														
							if ( measure eq "L" ) {
															
								sql = "SELECT 
											opt_name 
										FROM 
											query 
										WHERE 
											m_id = :measureId 
										ORDER BY 
											opt_idx";
							
								queryObj = new Query( dbtype="query" );
								queryObj.setAttributes( query=rs_options );
								queryObj.addParam( name="measureId", value=measureId, cfsqltype="cf_sql_char" );

								rs_opt = queryObj.execute( sql=sql ).getResult();

							}
														
						</cfscript>
													
						<cfif measure eq "L" >
							
							<!--- --->
							<cfscript>

								/* 生成已投票选项 */
								sql = "SELECT 
											a.answer, count(*) opt_count 
										FROM t_target_response a 
											INNER JOIN t_student_course b ON a.scc_id = b.scc_id 
										WHERE 
											a.tag_id = :targetId 
											AND 
											b.task_id = :taskId 
										GROUP BY a.answer";
			
								queryObj = new Query( datasource=application.dnsSlave );
								queryObj.addParam( name="targetId", value=targetId, cfsqltype="cf_sql_char" );
								queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
		
								rs_response = queryObj.execute( sql=sql ).getResult();
								
								optArray = [];
								
								for ( a=1; a LTE rs_opt.recordCount; a++ ) {
									arrayAppend( optArray, 0 );
								}
								
								for ( a=1; a LTE rs_response.recordCount; a++ ) {
									arraySet( optArray, rs_response["answer"][a], rs_response["answer"][a], rs_response["opt_count"][a] ); 
								}
			
							</cfscript>

							<tr class="cellBorder">
								<td><span class="numeric"><cfoutput>#L1#</cfoutput>.<cfoutput>#L2#</cfoutput></span></td>
								<td><cfoutput>#stringAdvice.XHTMLSafeFormat( rs_list.question )#</cfoutput></td>
								<td class="quota">
									<table>
										<tr>
											<cfloop query="rs_opt">
												<td nowrap="nowrap"><cfoutput>#rs_opt.opt_name#</cfoutput></td>
											</cfloop>
										</tr>
										<tr class="valued">
											<cfloop array="#optArray#" index="opt_count">
												<td><cfif opt_count gt 0><cfoutput>#opt_count#</cfoutput><cfelse>-</cfif></td>
											</cfloop>
										</tr>
									</table>
								</td>
							</tr>

						</cfif>
													
						<cfif measure eq "M" >

							<tr class="cellBorder">
								<td><span class="numeric"><cfoutput>#L1#</cfoutput>.<cfoutput>#L2#</cfoutput></span></td>
								<td><cfoutput>#stringAdvice.XHTMLSafeFormat( rs_list.question )#</cfoutput></td>
								<td class="quota">
									
								</td>
							</tr>
														
						</cfif>
											
					</cfloop>
				
				</cfif>
									
			</cfloop>
								
		</cfloop>

		</table>
		
		
	</cfif>


</cfif>